package Main;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public class Catalog {

	private ArrayList<Event> catalogEvents;
	
	public Catalog(String f)
	{
		catalogEvents=new ArrayList<Event>();
		loadEventFromFile(f);
	}
	
	private void loadEventFromFile(String catalogEventFile)
	{
		try {
			Scanner fileScanner;
			fileScanner = new Scanner(new FileInputStream(catalogEventFile));
			
			while(fileScanner.hasNext())
			{
				String line=fileScanner.nextLine();
				String[] splits=line.split("/");
				int hID = Integer.parseInt(splits[3]);
				int capacity=getHallCapacity(hID);
				Event readEvent=new Event(splits[0],splits[1],splits[2], hID,capacity);
				catalogEvents.add(readEvent);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public Event findEvent(String eName, int hID, String date, String time)
	{
		Event event=null;
		for(Event e : catalogEvents)
		{
			if(e.eventTitle.equals(eName) && e.hID==hID && e.eventDate.equals(date) && e.eventTime.equals(time))
			{
				event=e;
				break;
			}
			
			
		}
		if(event==null)
		{
			System.out.println(eName+" "+hID+" "+date+" "+time+"\nEvent is not found");
		}
		return event;
	}
	
	public int getHallCapacity(int id)
	{
		int capacity = 0;
		switch(id)
		{
		case 1:
			capacity=10;
			break;
		case 2:
			capacity=15;
			break;
		case 3:
			capacity=20;
			break;
		default:
			capacity=10;
			break;
		}
		return capacity;
	}
	
	public String toString()
	{
		String str="Catalog: " + "\n";
		for(Event e : catalogEvents)
		{
			str+=e + "\n";
		}
		return str;
	}
	
}
